package com.dindang.maintenance.mvp.model;

import android.app.Application;

import com.dindang.maintenance.mvp.model.api.service.CommonService;
import com.dindang.maintenance.mvp.model.entity.BaseResponse;
import com.dindang.maintenance.mvp.model.entity.Repair;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.dindang.maintenance.mvp.contract.SendOrderContract;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;


@ActivityScope
public class SendOrderModel extends BaseModel implements SendOrderContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public SendOrderModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<BaseResponse<List<Repair.MaintenancePeople>>> findRepairsByCorp(Repair.FindRepairsByCorpParam param) {
        Observable<BaseResponse<List<Repair.MaintenancePeople>>> base = mRepositoryManager.obtainRetrofitService(CommonService.class)
                .findRepairsByCorp(param.repId,
                        param.corpId);
        return base;
    }

    @Override
    public Observable<BaseResponse> insertFlow(Repair.AddFlowParam param) {
        Map<String, String> map = new HashMap<>();
        map.put("cType", param.cType);
        map.put("dAppointDate", param.dAppointDate);
        map.put("cStartDate", param.cStartDate);
        map.put("cEndDate", param.cEndDate);
        map.put("cRemark", param.cRemark);
        map.put("executorId", param.executorId);
        map.put("executor", param.executor);
        Observable<BaseResponse> base = mRepositoryManager.obtainRetrofitService(CommonService.class)
                .insertFlow(param.cRepId,
                        param.cCorpid,
                        param.cCreator,
                        param.cCreatorid,
                        param.cStatus,
                        map);
        return base;
    }
}